/**
 * Program  : TabBarActivity.java
 * Author   : qianj
 * Create   : 2012-5-24 下午05:34:19
 *
 * Copyright 2012 by newyulong Technologies Ltd.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of newyulong Technologies Ltd.("Confidential Information").  
 * You shall not disclose such Confidential Information and shall 
 * use it only in accordance with the terms of the license agreement 
 * you entered into with newyulong Technologies Ltd.
 *
 */
package cn.learn.easy;
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost.TabSpec;


/**
 * 拥有tabbar的基本activity
 * 
 * @author qianj
 * @version 1.0.0
 * @2012-5-24 下午05:34:19
 */
public class TabBarActivity extends ActivityGroup implements
		OnCheckedChangeListener {

	private RadioGroup group;

	public static final String TAB_ITEM_1 = "tabItem1";
	public static final String TAB_ITEM_2 = "tabItem2";
	public static final String TAB_ITEM_3 = "tabItem3";

	private TabHost tabHost;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tabbar);
		group = (RadioGroup) findViewById(R.id.tabbar_radio_group);
		group.setOnCheckedChangeListener(this);

		tabHost = (TabHost) findViewById(R.id.tabhost);
		tabHost.setup(this.getLocalActivityManager());

		TabSpec tab1 = tabHost.newTabSpec(TAB_ITEM_1);
		TabSpec tab2 = tabHost.newTabSpec(TAB_ITEM_2);
		TabSpec tab3 = tabHost.newTabSpec(TAB_ITEM_3);

		tab1.setIndicator(TAB_ITEM_1).setContent(
				new Intent(this, OneActivity.class));
		tab2.setIndicator(TAB_ITEM_2).setContent(
				new Intent(this, TwoActivity.class));
		tab3.setIndicator(TAB_ITEM_3).setContent(
				new Intent(this, OneActivity.class));
	

		tabHost.addTab(tab1);
		tabHost.addTab(tab2);
		tabHost.addTab(tab3);

		
		tabHost.setCurrentTab(0);
		RadioButton rb = (RadioButton)group.getChildAt(0);
		rb.setChecked(true);
		
		
	}

	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId) {
		switch (checkedId) {
		case R.id.radio_button1:
			tabHost.setCurrentTabByTag(TAB_ITEM_1);
			break;
		case R.id.radio_button2:
			tabHost.setCurrentTabByTag(TAB_ITEM_2);
			break;
		case R.id.radio_button3:
			tabHost.setCurrentTabByTag(TAB_ITEM_3);
			break;
		
		default:
			break;
		}

	};

}
